package com.ps.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ps.pojo.User;
import com.ps.mapper.UserMapper;
import com.ps.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-12-18
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public Page<User> getAll(Integer page,Integer limit,User user) {
        Page<User> userPage=new Page<>(page,limit);
        QueryWrapper<User> wrapper=new QueryWrapper<>();
        wrapper.eq(user.getRoleid()>0,"roleid",user.getRoleid());
        wrapper.like(user.getUsername()!=null&&!user.getUsername().equals(""),"username",user.getUsername());
        Page<User> all = userMapper.getAll(userPage, wrapper);
        return all;
    }

    @Override
    public boolean add(User user) {
        return userMapper.insert(user)>0;
    }

    @Override
    public boolean delet(Integer[] ids) {
        boolean flag=true;
        for (Integer id:ids){
            if (userMapper.deleteById(id)==0){
                flag=false;
            }
        }
        return flag;
    }
}
